import java.util.Arrays;
import java.util.Collections;

public class Summarize16 {
    private Integer[] sq = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
    private void print() {
        System.out.println("+----+----+----+----+");
        System.out.println("| " + form(0) + " | " + form(1) + " | " + form(2) + " | " + form(3) + " |");
        System.out.println("+----+----+----+----+");
        System.out.println("| " + form(4) + " | " + form(5) + " | " + form(6) + " | " + form(7) + " |");
        System.out.println("+----+----+----+----+");
        System.out.println("| " + form(8) + " | " + form(9) + " | " + form(10) + " | " + form(11) + " |");
        System.out.println("+----+----+----+----+");
        System.out.println("| " + form(12) + " | " + form(13) + " | " + form(14) + " | " + form(15) + " |");
        System.out.println("+----+----+----+----+");
    }
    private String form(int a) {
        int val = this.sq[a];
        if(val <= 9) {
            return " " + val;
        }
        return "" + val;
    }
    private static boolean isMaxArr(Integer[] arr) {
        for(int i = 0; i < arr.length - 1; i++) {
            for(int j = i + 1; j < arr.length; j++) {
                if(arr[i] < arr[j]){
                    return false;
                }
            }
        }
        return true;
    }
    private boolean isLineEqual34(int a, int b, int c, int d) {
        if(this.sq[a] + this.sq[b] + this.sq[c] + this.sq[d] == 34) {
            return true;
        }
        return false;
    }
    private void swapValByIdx(int idx1, int idx2) {
        int tmp = this.sq[idx1];
        this.sq[idx1] = this.sq[idx2];
        this.sq[idx2] = tmp;
    }
    private int findChangeIdx() {
        for(int i = this.sq.length - 1; i > 0; i--) {
            if(this.sq[i] > this.sq[i - 1]) {
                return i - 1;
            }
        }
        return -1;
    }
    private int findNextIdxByIdx(int fromIdx) {
        int fromNum = this.sq[fromIdx];     // 基值
        int miniNum = 17;                   // 最小值
        int idx = 15;
        for(int i = fromIdx; i < this.sq.length; i++) {
            if(this.sq[i] > fromNum) {
                if(this.sq[i] < miniNum) {
                    miniNum = this.sq[i];
                    idx = i;
                }
            }
        }
        return idx;
    }
    private void reSortFromIdx(int idx) {
        if(idx >= this.sq.length - 2) {
            return ;
        }
        Arrays.sort(this.sq, idx + 1, this.sq.length);
    }
    private void next() {
        if(isMaxArr(this.sq)) {
            return;
        }else {
            int idx = findChangeIdx();
            int nextNumIdx = findNextIdxByIdx(idx);
            this.swapValByIdx(idx, nextNumIdx);
            this.reSortFromIdx(idx);
        }
    }
    private void sort() {
        while(!isMaxArr(this.sq)) {
            boolean r1 = this.isLineEqual34(0, 1, 2, 3);
            if(!r1) {
                Arrays.sort(this.sq, 4, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean xf1 = this.isLineEqual34(0, 1, 4, 5);
            if(!xf1) {
                Arrays.sort(this.sq, 6, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean xf2 = this.isLineEqual34(1, 2, 5, 6);
            if(!xf2) {
                Arrays.sort(this.sq, 7, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean r2 = this.isLineEqual34(4, 5, 6, 7);
            boolean xf3 = this.isLineEqual34(2, 3, 6, 7);
            if(!r2 || !xf3) {
                Arrays.sort(this.sq, 8, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean xf4 = this.isLineEqual34(4, 5, 8, 9);
            if(!xf4) {
                Arrays.sort(this.sq, 10, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean xf5 = this.isLineEqual34(5, 6, 9, 10);
            if(!xf5) {
                Arrays.sort(this.sq, 11, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean r3 = this.isLineEqual34(8, 9, 10, 11);
            boolean xf6 = this.isLineEqual34(6, 7, 10, 11);
            if(!r3 || ! xf6) {
                Arrays.sort(this.sq, 12, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean c1 = this.isLineEqual34(0, 4, 8, 12);
            if(!c1) {
                Arrays.sort(this.sq, 13, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean q2 = this.isLineEqual34(3, 6, 9, 12);
            if(!q2) {
                Arrays.sort(this.sq, 13, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean c2 = this.isLineEqual34(1, 5, 9, 13);
            if(!c2) {
                Arrays.sort(this.sq, 14, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean xf7 = this.isLineEqual34(8, 9, 12, 13);
            if(!xf7) {
                Arrays.sort(this.sq, 14, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean xf8 = this.isLineEqual34(9, 10, 13, 14);
            if(!xf8) {
                Arrays.sort(this.sq, 15, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean c3 = this.isLineEqual34(2, 6, 10, 14);
            if(!c3) {
                Arrays.sort(this.sq, 15, this.sq.length, Collections.reverseOrder());
                this.next();
                continue;
            }
            boolean q1 = this.isLineEqual34(0, 5, 10, 15);
            if(!q1) {
                this.next();
                continue;
            }
            if(r1 && r2 && r3 && c1 && c2 && c3 && q1 && q2) {
                this.print();
                System.out.println("");
            }
            this.next();
        }
    }
    public static void main(String[] args) {
        Summarize16 sm = new Summarize16();
        sm.sort();
    }

}
